﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web.Configuration;

namespace TFSBuildLight.Providers
{
    class BuildLightProviderManager
    {
        private static BuildLightProvider provider;
        private static BuildLightProviderCollection providers;

        static BuildLightProviderManager()
        {
            Initialize();
        }
        
        private static void Initialize()
        {
            try
            {
                BuildLightProviderConfiguration configuration = (BuildLightProviderConfiguration)ConfigurationManager.GetSection("BuildLightProvider");

                if (configuration == null)
                {
                    throw new ConfigurationErrorsException("BuildLightProvider section is not setup properly.");
                }

                providers = new BuildLightProviderCollection();

                ProvidersHelper.InstantiateProviders(configuration.Providers, providers, typeof(BuildLightProvider));

                providers.SetReadOnly();

            }
            catch(Exception ex)
            {
                throw;
            }
        }

        public static BuildLightProvider Provider
        {
            get { return provider; }
        }

        public static BuildLightProviderCollection Providers
        {
            get { return providers; }
        }
    }
}
